package org.example.util;

import org.apache.http.HttpEntity;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * @ClassName : PageDownLoadUtil  //类名
 * @Description : 页面下载工具类  //描述
 * @Author : 易嵘  //作者
 * @Date: 2021-03-03 16:14  //时间
 */
public class PageDownLoadUtil {

    public static String getPageContent(String url)  {
        HttpClientBuilder builder = HttpClients.custom();
        CloseableHttpClient client = builder.build();

        HttpGet httpGet = new HttpGet(url);
        String content = null;
        try {
            CloseableHttpResponse response = client.execute(httpGet);
            HttpEntity entity = response.getEntity();

            content=EntityUtils.toString(entity,"UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return content;
    }

    public static void main(String[] args) {
        String url = "https://v.youku.com/v_show/id_XNTEwMTg0NjE5Mg==.html?spm=a2ha1.14919748_WEBHOME_GRAY.drawer7.d_zj1_4&s=ceba4745ea10415eb791&scm=20140719.manual.2556.show_ceba4745ea10415eb791&s=ceba4745ea10415eb791";
        String content = getPageContent(url);
        System.out.println(content);
    }

}
